package com.xl.singletonPattern;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 配置管理器
 */
public class ConfigManager {
    private static class ConfigManagerHolder {
        private static final ConfigManager instance = new ConfigManager();
    }

    private Properties config;
    private ConfigManager() {
        loadConfig();
    }

    public static ConfigManager getInstance() {
        return ConfigManagerHolder.instance;
    }

    private void loadConfig() {
        config = new Properties();
        try (InputStream input = ConfigManager.class.getClassLoader().getResourceAsStream("config.properties")) {
            if (input != null) {
                config.load(input);
            } else {
                System.out.println("配置文件未找到");
            }
        } catch (IOException e) {
            System.out.println("加载配置文件出错...");
        }
    }

    public String getProperty(String key) {
        return config.getProperty(key);
    }

}
